package com.wei.czz.common.vo.admin.menu;

import com.wei.czz.common.enums.admin.menu.MenuTypeEnum;
import com.wei.czz.common.jsr303.group.Save;
import com.wei.czz.common.jsr303.group.Update;
import com.wei.czz.common.tool.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2021-03-15 10:30:18
 * className: MenuVo 系统菜单请求参数封装Vo类
 * version: 1.1
 * description:
 */
@Getter
@Setter
@Accessors(chain = true)
public class MenuVo extends BaseEntity {

    /**
     * 菜单id
     */
    @NotNull(message = "菜单主键不能为空", groups = { Update.class })
    private Long menuId;

    /**
     * 父菜单ID，一级菜单为0
     */
    @NotNull(message = "父级菜单主键不能为空", groups = { Save.class, Update.class })
    private Long parentId;

    /**
     * 父级菜单路径
     */
    @NotNull(message = "父级路径不能为空", groups = { Save.class, Update.class })
    private String menuPath;

    /**
     * 菜单名称
     */
    @NotBlank(message = "菜单名称不能为空", groups = { Save.class, Update.class })
    private String name;

    /**
     * 菜单类型[0-目录 1-页面 2-按钮]
     */
    @NotNull(message = "菜单类型不能为空", groups = { Save.class, Update.class })
    private Integer type;

    /**
     * 菜单路径
     */
    private String path;

    /**
     * 权限标识(多个用逗号分隔，如：user:add,user:update)
     */
    private String permit;

    /**
     * 菜单图标
     */
    private String icon;

    /**
     * 排序等级
     */
    @NotNull(message = "排序等级不能为空", groups = { Save.class, Update.class })
    private Integer sort;

    /**
     * 显示状态[0-显示 1-隐藏]
     */
    @NotNull(message = "显示状态不能为空", groups = { Save.class, Update.class })
    private Integer display;

    /**
     * 校验批量保存请求参数是否有误
     * @return true-校验拒绝 false-校验通过
     */
    public boolean isBatchSaveParamsFail() {
        if (ObjectUtils.anyNull(menuId, parentId, name, type, sort, display)) {
            return true;
        }
        if (MenuTypeEnum.PACKAGE_TYPE.getValue().equals(type)) {
            // 目录菜单
            return StringUtils.isBlank(icon);
        }
        if (MenuTypeEnum.PAGE_TYPE.getValue().equals(type)) {
            // 页面菜单
            return StringUtils.isAnyBlank(path, icon);
        }
        if (MenuTypeEnum.BUTTON_TYPE.getValue().equals(type)) {
            // 按钮 菜单
            return StringUtils.isBlank(permit);
        }
        return false;
    }

}
